package com.snopy.controller;

import com.alibaba.fastjson.JSONObject;
import com.snopy.pojo.JSONResult;
import com.snopy.pojo.User;
import lombok.extern.slf4j.Slf4j;
import nonapi.io.github.classgraph.json.JSONUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;

/**
 * @author snopy
 * @version 1.0.0
 * @classname QuestionController
 * @description
 * @email 77912204@qq.com
 * @date 2022/08/15 11:00
 */

@Slf4j
@RestController
@RequestMapping("/ask")
public class QuestionController {

    @PostMapping("/login")
    @ResponseBody
    public JSONObject login(String username,String password, HttpServletRequest request,
                            HttpServletResponse response) throws IOException {

        //response.setHeader("Access-Control-Allow-Origin","*");
        log.info("username:{},password:{}",username,username);
        //PrintWriter writer = response.getWriter();
        Map<String,Object> result = new HashMap<>();
        result.put("status","200");
        //writer.println(new JSONObject(result));
        return new JSONObject(result);
    }
    @GetMapping("/getAnswer")
    public void GetAnseer(String question, HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setHeader("Access-Control-Allow-Origin","*");
        Map<String,Object> answer = new HashMap<>();
        if (question.contains("美女")){
            answer.put("answer","yes");
        }else {
            answer.put("answer","no");
        }
        
        PrintWriter writer = response.getWriter();
        writer.println(new JSONObject(answer));
        //return new JSONObject(answer);
    }
    @GetMapping("/getStatue")
    public void getStatue(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setHeader("Access-Control-Allow-Origin","*");
        Map<String,Object> answer = new HashMap<>();
        answer.put("answer","yes");
        answer.put("method","2");
        answer.put("status","ok");
        answer.put("message","success");
        PrintWriter writer = response.getWriter();
        writer.println(new JSONObject(answer));
        //return new JSONObject(answer);
    }

}
